package com.sugar.psych.assessment.module.business.controller.admin.configrisklevel;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.sugar.psych.assessment.framework.common.pojo.PageParam;
import com.sugar.psych.assessment.framework.common.pojo.PageResult;
import com.sugar.psych.assessment.framework.common.pojo.CommonResult;
import com.sugar.psych.assessment.framework.common.util.object.BeanUtils;
import static com.sugar.psych.assessment.framework.common.pojo.CommonResult.success;

import com.sugar.psych.assessment.framework.excel.core.util.ExcelUtils;

import com.sugar.psych.assessment.framework.apilog.core.annotation.ApiAccessLog;
import static com.sugar.psych.assessment.framework.apilog.core.enums.OperateTypeEnum.*;

import com.sugar.psych.assessment.module.business.controller.admin.configrisklevel.vo.*;
import com.sugar.psych.assessment.module.business.dal.dataobject.configrisklevel.ConfigRiskLevelDO;
import com.sugar.psych.assessment.module.business.service.configrisklevel.ConfigRiskLevelService;

@Tag(name = "管理后台 - 风险等级配置")
@RestController
@RequestMapping("/business/config-risk-level")
@Validated
public class ConfigRiskLevelController {

    @Resource
    private ConfigRiskLevelService configRiskLevelService;

    @PostMapping("/create")
    @Operation(summary = "创建风险等级配置")
    @PreAuthorize("@ss.hasPermission('business:config-risk-level:create')")
    public CommonResult<Long> createConfigRiskLevel(@Valid @RequestBody ConfigRiskLevelSaveReqVO createReqVO) {
        return success(configRiskLevelService.createConfigRiskLevel(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新风险等级配置")
    @PreAuthorize("@ss.hasPermission('business:config-risk-level:update')")
    public CommonResult<Boolean> updateConfigRiskLevel(@Valid @RequestBody ConfigRiskLevelSaveReqVO updateReqVO) {
        configRiskLevelService.updateConfigRiskLevel(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除风险等级配置")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('business:config-risk-level:delete')")
    public CommonResult<Boolean> deleteConfigRiskLevel(@RequestParam("id") Long id) {
        configRiskLevelService.deleteConfigRiskLevel(id);
        return success(true);
    }

    /*@DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除风险等级配置")
                @PreAuthorize("@ss.hasPermission('business:config-risk-level:delete')")
    public CommonResult<Boolean> deleteConfigRiskLevelList(@RequestParam("ids") List<Long> ids) {
        configRiskLevelService.deleteConfigRiskLevelListByIds(ids);
        return success(true);
    }*/

    @GetMapping("/get")
    @Operation(summary = "获得风险等级配置")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('business:config-risk-level:query')")
    public CommonResult<ConfigRiskLevelRespVO> getConfigRiskLevel(@RequestParam("id") Long id) {
        ConfigRiskLevelDO configRiskLevel = configRiskLevelService.getConfigRiskLevel(id);
        return success(BeanUtils.toBean(configRiskLevel, ConfigRiskLevelRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得风险等级配置分页")
    @PreAuthorize("@ss.hasPermission('business:config-risk-level:query')")
    public CommonResult<PageResult<ConfigRiskLevelRespVO>> getConfigRiskLevelPage(@Valid ConfigRiskLevelPageReqVO pageReqVO) {
        PageResult<ConfigRiskLevelDO> pageResult = configRiskLevelService.getConfigRiskLevelPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ConfigRiskLevelRespVO.class));
    }
}